import * as THREE from 'three'
import gsap from 'gsap'

// 飞线
export default class FlyLine {
  constructor() {
    let linePoints = [
      new THREE.Vector3(0, 0, 0),
      new THREE.Vector3(4, 4, 0),
      new THREE.Vector3(10, 0, 0),
    ]
    // 1、创建曲线
    this.linecurve = new THREE.CatmullRomCurve3(linePoints)
    // 2、根据曲线生成管道集合体
    this.geometry = new THREE.TubeGeometry(this.linecurve, 100, 0.4, 2, false)
    // 3、飞线材质
    // 创建纹理
    const textloader = new THREE.TextureLoader()
    this.texture = textloader.load('./textures/spriteline1.png')
    this.texture.repeat.set(1, 2)
    this.texture.wrapS = THREE.RepeatWrapping
    this.texture.wrapT = THREE.MirroredRepeatWrapping

    this.material = new THREE.MeshBasicMaterial({
      color: 0xfff000,
      map: this.texture,
      transparent: true,
    })

    // 创建飞线
    this.mesh = new THREE.Mesh(this.geometry, this.material)

    gsap.to(this.texture.offset, {
      x: -1,
      duration: 1,
      ease: 'none',
      repeat: -1,
    })
  }
}
